﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceability_2203.Common.Infrastructure.Interfaces;

namespace Traceability_2203.Common.Infrastructure.Repositories
{
    public class IdentityService : IIdentityService
    {
        private readonly IHttpContextAccessor httpContextAccessor;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="httpContextAccessor"></param>
        public IdentityService(IHttpContextAccessor httpContextAccessor)
        {
            this.httpContextAccessor = httpContextAccessor;
        }

        /// <summary>
        /// 从HTTP请求的上下文里取值
        /// </summary>
        public string UserId
        {
            get => httpContextAccessor.HttpContext.User.FindFirst("UserId")?.Value;
            set => throw new NotImplementedException();
        }
        public string UserName
        {
            get => httpContextAccessor.HttpContext.User.FindFirst("UserName")?.Value;
            set => throw new NotImplementedException();
        }
    }
}
